﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BLL;
using DAL.Linq.EntityMapper;

namespace DAL.Linq
{
    public class LinqDMKHACHHANG_Dao : IDMKHACHHANG_Dao
    {

        #region IDao<DMKHACHHANGInfo,string> Members

        /// <summary>
        /// Gets a list of all DMKHACHHANGs.
        /// </summary>
        /// <returns>List of DMKHACHHANGs.</returns>
        public IList<DMKHACHHANG> GetAll()
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Gets a specific DMKHACHHANG.
        /// </summary>
        /// <param name="maKhachHang">Unique MaKhachHang identifier.</param>
        /// <returns>DMKHACHHANG.</returns>
        public DMKHACHHANG GetById(string maKhachHang)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region IDMKHACHHANG_Dao Members

        public bool DM_KhachHang_Insert(string MaKhachHang, string TenKhachHang, string TenCongTy, string DiaChi, string DienThoai, string Fax, string Website, string TaiKhoan, string MaSoThue, bool IsUse, int CreateBy)
        {
            int bln = 0;
            using (Invoice db = DataContextFactory.CreateContext())
            {
                try
                {
                    bln = db.sp_DMKhachHang_Insert(MaKhachHang, TenKhachHang, TenCongTy, DiaChi, DienThoai, Fax, Website, TaiKhoan, MaSoThue, IsUse, CreateBy);
                    if (bln == 1)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                catch { return false; }
            }

        }

        public bool DM_KhachHang_Update(string MaKhachHang, string TenKhachHang, string TenCongTy, string DiaChi, string DienThoai, string Fax, string Website, string TaiKhoan, string MaSoThue, bool IsUse, int CreateBy, int ModifiedBy, DateTime ModifiedOn)
        {
            int bln = 0;
            using (Invoice db = DataContextFactory.CreateContext())
            {
                try
                {
                    bln = db.sp_DMKhachHang_Update(MaKhachHang, TenKhachHang, TenCongTy, DiaChi, DienThoai, Fax, Website, TaiKhoan, MaSoThue, IsUse, CreateBy,ModifiedBy,ModifiedOn );
                    if (bln == 1)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                catch { return false; }
            }    
        }

        public bool DM_KhachHang_Delete(string MaKhachHang)
        {
            int bln = 0;
            using (Invoice db = DataContextFactory.CreateContext())
            {
                try
                {
                    bln = db.Sp_DMKhachHang_Delete(MaKhachHang);
                    if (bln == 1)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                catch { return false; }
            }
        }

        public IList<DMKHACHHANG> GetAll_KhachHang()
        {
            List<DMKHACHHANG> lst = null;
            using (Invoice db = DataContextFactory.CreateContext())
            {
                try
                {
                    lst = db.sp_DMKhachHang_GetAll().Select(p => Mapper.ToBusinessObject(p)).ToList();
                }
                catch { }
                finally
                {
                    if (db != null)
                        db.Dispose();
                }
            }
            return lst;
        }

        #endregion
    }
}
